package com.situ.domain;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

public class SalesRecordModel implements Comparable<SalesRecordModel>, Serializable{
    
    /** serialVersionUID*/  
    private static final long serialVersionUID = 132511L;
    
    private int id; // 序号
    private int sex; // 顾客性别
    private String[] name; // 水果数组
    private double[] sellingPrice; // 水果单价数组
    private double[] weight; // 水果重量数组
    private double[] costs; // 水果费用数组
    private double totleCost; // 共计消费
    private Date date; // 消费时间

    private static int numId = 1;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    @Override
    public String toString() {
        String sexStr = "男";
        if (sex == 0) {
            sexStr = "女";
        }
        return "序号：" + id + "\t" + "顾客性别：" + sexStr + "\n水果名:" + Arrays.toString(name) + "\n售价/元:" + Arrays.toString(sellingPrice) + 
                "\n重量/Kg:" + Arrays.toString(weight) + "\n消费/元:" + Arrays.toString(costs) + "\n累计消费/元:" + totleCost + "\t\t" + sdf.format(date) + "\n";
    }

    @Override
    public int compareTo(SalesRecordModel o) {
        return this.id - o.getId();
    }

    public SalesRecordModel() {
        super();
        this.id = numId++;
    }

    public SalesRecordModel(int sex, String[] name, double[] sellingPrice, double[] weight) {
        this();
        this.sex = sex;
        this.name = name;
        this.sellingPrice = sellingPrice;
        this.weight = weight;
        double[] costs = new double[sellingPrice.length];
        double totleCost = 0.0;
        for (int i = 0; i < sellingPrice.length; i++) {
            costs[i] = sellingPrice[i] * weight[i];
            totleCost += costs[i];
        }
        this.costs = costs;
        if (sex == 0) {
            totleCost *= 0.8;
        }
        this.date = new Date();
        if (this.date.getHours() >= 17) {
            totleCost *= 0.5;
        }
        this.totleCost = totleCost;

    }

    // getter setter
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    
    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }
    
    public String[] getName() {
        return name;
    }

    public void setName(String[] name) {
        this.name = name;
    }

    public double[] getSellingPrice() {
        return sellingPrice;
    }

    public void setSellingPrice(double[] sellingPrice) {
        this.sellingPrice = sellingPrice;
    }

    public double[] getWeight() {
        return weight;
    }

    public void setWeight(double[] weight) {
        this.weight = weight;
    }

    public double[] getCosts() {
        return costs;
    }

    public void setCosts(double[] costs) {
        this.costs = costs;
    }

    public double getTotleCost() {
        return totleCost;
    }

    public void setTotleCost(double totleCost) {
        this.totleCost = totleCost;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public static int getNumId() {
        return numId;
    }

    public static void setNumId(int numId) {
        SalesRecordModel.numId = numId;
    }

    public SimpleDateFormat getSdf() {
        return sdf;
    }

    public void setSdf(SimpleDateFormat sdf) {
        this.sdf = sdf;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + Arrays.hashCode(costs);
        result = prime * result + ((date == null) ? 0 : date.hashCode());
        result = prime * result + id;
        result = prime * result + Arrays.hashCode(name);
        result = prime * result + ((sdf == null) ? 0 : sdf.hashCode());
        result = prime * result + Arrays.hashCode(sellingPrice);
        result = prime * result + sex;
        long temp;
        temp = Double.doubleToLongBits(totleCost);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        result = prime * result + Arrays.hashCode(weight);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        SalesRecordModel other = (SalesRecordModel) obj;
        if (!Arrays.equals(costs, other.costs))
            return false;
        if (date == null) {
            if (other.date != null)
                return false;
        } else if (!date.equals(other.date))
            return false;
        if (id != other.id)
            return false;
        if (!Arrays.equals(name, other.name))
            return false;
        if (sdf == null) {
            if (other.sdf != null)
                return false;
        } else if (!sdf.equals(other.sdf))
            return false;
        if (!Arrays.equals(sellingPrice, other.sellingPrice))
            return false;
        if (sex != other.sex)
            return false;
        if (Double.doubleToLongBits(totleCost) != Double.doubleToLongBits(other.totleCost))
            return false;
        if (!Arrays.equals(weight, other.weight))
            return false;
        return true;
    }

}
